if(undefined == community_smartstream){
    var community_smartstream = (function(){
        var _pageSize = 10,
            _offset = '' ,
            _tlatest = '',
            _latest = false,
            _filter = '0' ,
            _order='0',
            _displayStatus = 1,//1:max page; 2:search page
            _next = true ,
            _prev = true,
            _insertOrder = true,
            _searchOffset = '',
            _searchKeyword = '',
            _searchCount = 0,
            _communityID = '',
            _communityName = '',
			_loader = '',
            _enableJoin = '';
        var maxTmpl = $('#community_smartstream_maxTmpl').html(),
            maxPageTmpl = $('#community_ss_body_max'),
            searchPageTmpl = $('#community_ss_body_search'),
            searchResultContainer = $('#community_ss_body_search_result_container'),
            searchResultPageTmpl = $('#community_ss_body_search_results');

        var communityDocuments;

        var type2Icon = {xlsx:'main_documents_o_20_20', xls:'main_documents_o_20_20', tif:'main_documents_t_20_20', tiff:'main_documents_t_20_20', docx:'main_documents_e_20_20', doc:'main_documents_e_20_20', pdf:'main_documents_f_20_20', ppt:'main_big_k_20_20', pptx:'main_big_k_20_20', txt:'main_big_n_20_20', zip:'main_big_m_20_20'};

        var window_liked_users, winNominateExpertsList, userListScroll, userListWinHtml;
        var useragent = Workport.getBrowser();
        var win = $('#community_smartstream_window').kendoWindow({
            width:750,
            height:600,
            visible : false,
            draggable: false,
            resizable: false,
            modal: true            
        });
        $('#community_smartsteam_panel').appendTo(win);
        win.data('kendoWindow').center();
        win.data('kendoWindow').close();

        function resetUI () {
            _offset = '' ,
                _tlatest = '',
                _latest = false,
                _filter = '0' ,
                _order='0',
                _displayStatus = 1,//1:max page; 2:search page
                _next = true ,
                _prev = true,
                _insertOrder = true,
                _searchOffset = '',
                _searchKeyword = '',
                _searchCount = 0,
                _communityID = '',
                _communityName = '';

            maxPageTmpl.off('*');
            maxPageTmpl.empty();
            searchResultPageTmpl.off('*');
            searchResultPageTmpl.empty();

            $('#community_filterMenu').show();
            $('#community_document_filter').hide();

            $('#community_menu_icons_for_stream_selected').show();
            $('#community_menu_icons_for_document_selected').hide();

            $('#community_order_for_stream').show();
            $('#community_order_for_document').hide();

            $('#community_ss_body_max').show();
            $('#community_document_max').hide();
            $('community_ss_body_search').hide();

            $('#smartskipicon').remove();

            $('.community_stream_count').text('(0)');
            if(_order == '0') {
                $('#community_ss_order_hottest').css('color','#000000');
                $('#community_ss_order_recent').css('color','#a6a6a6');
            } else {
                $('#community_ss_order_hottest').css('color','#a6a6a6');
                $('#community_ss_order_recent').css('color','#000000');
            }
        }
        function updateStat () {
            Workport.CommunityAPI.getStat(function (data) {

                if (data && data.CommunityStatistics) {
                    for (var i = 0; i < data.CommunityStatistics.length; i ++) {
                        var obj = data.CommunityStatistics[i];
                        var count = obj.Count;
                        var html = '('+count+')';
                        switch (obj.EntityName) {
                            case 'Update':
                                $('.community_stream_count').text(html);
                                break;
                            case 'Documents':
                                $('.community_document_count').text(html);
                                break;
                        }
                    }
                }

            }, {communityId: _communityID, sync : true});
        }

        return{
            init:function(outContainner, communityId, communityName, enableJoind){
                _communityID = communityId;
                _communityName = communityName;
                _enableJoin = enableJoind;
                communityDocuments = new Export_CommunityDocs_ScrollViewController($('#community_document_max'), _communityID);
                communityDocuments.init();

                var self = this;
                var height = $(window).height() - 120;

                if(useragent == 'ipad'){
                    maxPageTmpl.css('width','750px');
                    maxPageTmpl.css('height','560px');
                    maxPageTmpl.css('overflow-y','scroll');
                    searchResultPageTmpl.css('width','750px');
                    searchResultPageTmpl.css('height','500px');
                    searchResultPageTmpl.css('overflow-y','scroll');
                    $('#community_ss_body_max').bind("scroll",function(){
                        if($('#community_ss_body_max').scrollTop() == 0){ //top
                            self.doTop();
                        } 
                        else if($('#community_ss_body_max')[0].scrollHeight <= $('#community_ss_body_max').scrollTop() + $('#community_ss_body_max').height()){
                            self.append();
                        }
                    });
                    $('#community_ss_body_search_results').bind("scroll",function(){
                        if($('#community_ss_body_search_results').scrollTop() == 0){ //top
                            //self.doTop();
                        } 
                        else if($('#community_ss_body_search_results')[0].scrollHeight <= $('#community_ss_body_search_results').scrollTop() + $('#community_ss_body_search_results').height()){
                            self.append();
                        }
                    });
                } else{
                        maxPageTmpl.slimscroll({
                            wheelStep : 20,
                            width : 750,
                            height : 560,
                            start : 'top',
                            disableFadeOut:true,
                            touchScrollStep : 200
                        });
                        maxPageTmpl.slimScroll().bind('slimscroll',function(e,pos){
                            if('bottom' ==  pos){
                                self.append();
                            }
                            if('top' == pos){
                            //  self.doTop();
                            }
                        });
                        searchResultPageTmpl.slimscroll({
                            wheelStep : 20,
                            width : 750,
                            height : 500,
                            start : 'top',
                            disableFadeOut:true,
                            touchScrollStep : 200
                        });
                        searchResultPageTmpl.slimScroll().bind('slimscroll',function(e,pos){
                            if('bottom' ==  pos){
                                self.append();
                            }
                            if('top' == pos){
                                //self.doTop();
                            }
                        });
                }
                searchPageTmpl.hide();
                //filter
                {
                    var listInnerHTML = '<li value="0">All</li>' +
                        '<li value="1">Bookmark</li>' +
                        '<li value="2">Unanswered</li>';
                    $('#community_filterMenu_list').html(listInnerHTML);
                    $('#community_filterMenu').kendoMenu({
                        select: function (e) {
                            if( e.item.attributes.value != undefined){
                                 self.onFilterClicked(e);
                            }
                        }
                    });
                }
                {
//                    $('#community_document_filter').kendoMenu({
//                        select: function (e) {
//                        }
//                    });
                }

                //windows
                window_liked_users = $('#community_ss_window_liked_users');
                userListWinHtml = window_liked_users.html();
                
                window_liked_users.kendoWindow({
                    width:384,
                    height:'auto',
                    title:"Liked Users",
                    visible:false,
                    model:true,
                    draggable: false,
                    resizable: false,
                    modal: true,
                    actions:["Close"],
                    close:function(){
                        window_liked_users.empty();
                        window_liked_users.html(userListWinHtml);
                    }
                });

				$('#community_filterMenu_selected').text("Filter Posts");
				self._loader = new Workport.Loader($('#community_ss_body_max'),{position:'center',text:'Loading',imgColor:'black',hasMask:false,textCSS:{'color':'black'}});
                self.maxTmp();
            },
            maxTmp:function(){
                var self = this;
                _displayStatus = 1;
                _offset = '';
                _next = false;
                _prev = true;
                _tlatest = '';
                _latest = false;
				maxPageTmpl.off('*');
                maxPageTmpl.empty();
				self._loader.setContent($('#community_ss_body_max'), {hasMask:false,imgColor:'black',position:'center',textCSS:{'color':'black'}});
				self._loader.show();
				$.when(Workport.StreamAPI.getCommunityDetail(null,{communityId : _communityID, pageSize:_pageSize,pagePosition:'',filter:_filter,order:_order}),
				Workport.CommunityAPI.getStat(null,{communityId: _communityID, sync : true}),
				Workport.StreamAPI.getMentionUsers(null,{targetID: _communityID,type:"C"})
				).done(function(r1,r2,r3){
					var _data = $.parseJSON(r1[2].responseText);
					var data = $.parseJSON(r2[2].responseText);
					WP_MENTION_COMM = $.parseJSON(r3[2].responseText).Users;
					
					self._loader.hide();
					
                    if(_data && $.isArray(_data.Notifications)){
                        _next = true;
                        if (_data.ResponseCode == 'WP1005') {
                            _next = false;
                        }
                        self.render(_data.Notifications);
                        _offset = _data.Notifications.pop().PagePosition;
                        if (_data.Notifications.length) {
                            _tlatest = _data.Notifications.shift().PagePosition;
                        } else {
                            _tlatest = _offset;
                        }
                    } else {
                        if (_displayStatus == 1 && !_offset && _filter == '0' && _tlatest == '') {
                            $('#community_ss_body_max').html('<div id="ss_topic_began" style="margin-left: 485px;"><img src="imgs/beganSmartSream.png"></div>');
                            $('#community_ss_body_max').css('margin-top','0px');
							$('#community_smartsteamTpl').find('.main_common_j_11_11').removeClass('smartsteam_clickable');
                            setTimeout(function(){
                                $('#ss_topic_began').hide();
                            },2000)
                        } else {
                            $('#community_ss_body_max').css('margin-top','15px');
							 var innerHtml = '<div style="text-align: center;"><span id="community_ss_no_result_max" >No results found for the selected filter criteria.</span></div>';
							$('#community_ss_body_max').html(innerHtml);
                        }
                    }
					
					if (data && data.CommunityStatistics) {
						for (var i = 0; i < data.CommunityStatistics.length; i ++) {
							var obj = data.CommunityStatistics[i];
							var count = obj.Count;
							var html = '('+count+')';
							switch (obj.EntityName) {
								case 'Update':
									$('.community_stream_count').text(html);
									break;
								case 'Documents':
									$('.community_document_count').text(html);
									break;
							}
						}
					}
				});
				/*
                Workport.StreamAPI.getCommunityDetail(function(_data){
					loader.hide();
                    maxPageTmpl.off('*');
                    maxPageTmpl.empty();
                    if(_data && $.isArray(_data.Notifications)){
                        _next = true;
                        if (_data.ResponseCode == 'WP1005') {
                            _next = false;
                        }
                        self.render(_data.Notifications);
                        _offset = _data.Notifications.pop().PagePosition;
                        if (_data.Notifications.length) {
                            _tlatest = _data.Notifications.shift().PagePosition;
                        } else {
                            _tlatest = _offset;
                        }
                    } else {
                        if (_displayStatus == 1 && !_offset && _filter == '0' && _tlatest == '') {
                            $('#community_ss_body_max').html('<div id="ss_topic_began" style="margin-left: 485px;"><img src="imgs/beganSmartSream.png"></div>');
                            $('#community_ss_body_max').css('margin-top','0px');
							$('#community_smartsteamTpl').find('.main_common_j_11_11').removeClass('smartsteam_clickable');
                        } else {
                            $('#community_ss_body_max').css('margin-top','15px');
							 var innerHtml = '<div style="text-align: center;"><span id="community_ss_no_result_max" >No results found for the selected filter criteria.</span></div>';
							$('#community_ss_body_max').html(innerHtml);
                        }
                    }
                    updateStat();
                },{communityId : _communityID, pageSize:_pageSize,pagePosition:'',filter:_filter,order:_order});
				*/
            },
            getAppIcon:function(type){
                var className = 'main_documents_e_20_20';
                if (type2Icon[type]) {
                    className = type2Icon[type];
                }
                return '<i class="'+className+'"></i>';
            },
            doTop:function(){
                if (!_next) {
                    return;
                }
                var self = this;
                _insertOrder = false;
                _latest = true;
                _prev = false;
                switch (_displayStatus) {
                    case 0:
                        break;
                    case 1:
						self._loader.setContent($('#community_ss_body_max'),{position:'up',text:'',hasMask:false,imgColor:'black',textCSS:{'color':'black'}});
						self._loader.show();
                        Workport.StreamAPI.getCommunityDetail(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.Notifications)){
                                self.render(_data.Notifications);
                                if (_data.Notifications.length) {
                                    _tlatest = _data.Notifications.shift().PagePosition;
                                }
                            }
                            _next = true;
                        },{communityId : _communityID, pageSize:_pageSize,pagePosition:_latest,filter:_filter,order:_order});
                        break;
                    case 2:
                        break;
                    default :
                        break;
                }
            },
            append:function(){
                if (!_next) {
                    return;
                }
                var self = this;
                _latest = false;
                _insertOrder = true;
                _next =false;
				var loader;
                switch (_displayStatus) {
                    case 0:
                        break;
                    case 1:
						self._loader.setContent($('#community_ss_body_max'),{position:'down',text:'',hasMask:false,imgColor:'black',textCSS:{'color':'black'}});
						self._loader.show();
                        Workport.StreamAPI.getCommunityDetail(function(_data){
							self._loader.hide();
                            if(_data && $.isArray(_data.Notifications)){
                                _next = true;
                                if (_data.ResponseCode == 'WP1005') {
                                    _next = false;
                                }
                                self.render(_data.Notifications);
                                _offset = _data.Notifications.pop().PagePosition;
                            }
                        },{communityId : _communityID, pageSize:_pageSize,pagePosition:_offset,filter:_filter,order:_order});
                        break;
                    case 2:
                        var data = {key:_searchKeyword,pageSize:_pageSize,type:"U", offset : _searchOffset,sync:true};
						self._loader.setContent($('#community_ss_body_search_results'),{position:'down',text:'',hasMask:false,imgColor:'black',textCSS:{'color':'black'}});
						self._loader.show();
                        Workport.StreamAPI.searchStream(function(_d,_code) {
							self._loader.hide();
                            if(!_d){
                                Workport.utils.alertMsg("", 'network error!', function(_data){});
                                return ;
                            }
                            if(!_d.notification){

                            }else {
                                _next = true;
                                if (_d.ResponseCode == 'WP1005') {
                                    _next = false;
                                }
                                searchResultContainer.show();
                                self.render(_d.notification);
                                _searchCount += _d.notification.length;
                                _searchOffset = _d.notification.pop().LastModifiedDate;
                                $('#community_ss_body_search_count').text(' > Showing ' +_searchCount + ' result(s) for ' + _searchKeyword);
                                if (_searchCount == 0) {
                                    searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                                }
                            }
                        }, data);
                        break;
                    default :
                        break;
                }
            },
            deleteRow:function(obj){
                $('#community_'+obj.id+',#community_'+obj.id+'_line').remove();
                Workport.utils.alertMsg("Delete",'Deleting the update will also delete all attachments associated with  the update. Are you sure you want to delete the update?',"Delete",function(_is){
                    if(_is==true){
                        Workport.StreamAPI.deleteStream(function(_d,_c){
                            if(_d) {
                                if (_d.ResponseCode == "WP1008") {
                                    $('#community_max_' + obj.id).remove();
                                    $('#community_max_' + obj.id + '_line').remove();
                                    Workport.utils.alertMsg("", "Your update has been deleted successfully.", function (_data) {
                                        updateStat();
                                    });
                                } else if (_d.ResponseCode == "WP1007"){
									 Workport.utils.alertMsg("", "The update cannot be deleted. A document associated with this update has been checked out.", function () {});
								} else {
                                    Workport.utils.alertMsg("", _d.ResponseMessage, function () {
                                    });
                                }
                            }
                        },obj);
                    }
                });
            },
            isliked:function(obj,param){
				var _self = this;
				if(this.isLiked)
					return;
				this.isLiked = true;
                var isLikeMark =  $(obj).attr('status') ;
                isLikeMark = isLikeMark == 'false' ? 'true' :'false';
                param.action = isLikeMark == 'true'? 0 : 1 ;
                Workport.StreamAPI.postLike(function(_d,_c){
					_self.isLiked = false;
                    if(_d.ResponseCode=="WP1008"){
                        $(obj).attr('status',isLikeMark);
                        $(obj).attr('class',isLikeMark == 'true'? 'main_smartstream_t_8_8 smartsteam_clickable':'main_smartstream_w_8_8 smartsteam_clickable');
                        var linksCount = $(obj).parent().find('.likesCount')[0];
						if (isLikeMark == 'true'){
							$(obj).attr('title', 'You have Liked this');
							linksCount.innerHTML = parseInt(linksCount.innerHTML)+1;
							$(linksCount).attr('class', 'likesCount smartsteam_clickable');
						}
						else {
							$(obj).attr('title', 'Like this');
							linksCount.innerHTML = parseInt(linksCount.innerHTML)-1;
							if(linksCount.innerHTML == 0)
								$(linksCount).removeClass('smartsteam_clickable');
						}
                      
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(){});
                    }
                },param);
            },
            bookmark:function(obj,param){
                var isBookmark =  $(obj).attr('status') ;
                isBookmark = isBookmark == 'false' ? 'true' :'false';
                param.action = isBookmark == 'true'? 0 : 1 ;
                Workport.StreamAPI.bookmark(function(_d,_c){
                    if(_d.ResponseCode=="WP1008"){
                        $(obj).attr('status',isBookmark);
                        $(obj).attr('class',isBookmark == 'true'? 'main_smartstream_ab_8_8 smartsteam_clickable':'main_smartstream_aa_8_8 smartsteam_clickable');
                        $(obj).attr('title', isBookmark == 'true'? 'Unbookmark':'Bookmark');
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(_data){});
                    }
                },param);
            },
            subscribe:function(obj,param){
                var isSubscribe = $(obj).attr('status') ;
                isSubscribe = isSubscribe == 'false' ? 'true' :'false';
                param.action = isSubscribe == 'true'? 0 : 1 ;
                if(param.notificationType.toLowerCase() == 'c'){
                    Workport.StreamAPI.subscriptionMail(function(_d,_c){
                        if(_d.ResponseCode=="WP1008"){
                            $(obj).attr('status',isSubscribe);
                            $(obj).attr('class',isSubscribe == 'true'? 'main_calendar_t_8_8 smartsteam_clickable':'main_calendar_u_8_8 smartsteam_clickable');
                            $(obj).attr('title',isSubscribe == 'true'? 'Stop Mail Alerts':'Receive Mail Alerts');
                        }else{
                            Workport.utils.alertMsg("", _d.ResponseMessage, function(_data){});
                        }
                    },param);
                }
            },
            default:function(obj){
                $(obj).hide();
                $(obj).parent('.pic').css({'background':'url(imgs/img20.png)'});
            },
            setDefaultIcon:function(obj){
                $(obj).attr({'src':'imgs/img20.png'});
            },
            toSingleImg:function(obj){
                $(obj).addClass('ss_single_person_icon');
                $(obj).attr('src','imgs/UserDefault.png');
            },
            toMultiImg:function(obj){
                $(obj).addClass('ss_multi_person_icon');
                $(obj).attr('src','imgs/CommunityDefault.png');
            },
            showDetailWindowWithURL :  function (source,url,notID,notType,tagID,creatDate,notText,commentListPageSize){
                var cb = function () {
                    Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null){
                            Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                            return;
                        }

                        //var rowTmpl = maxTmpl;
						var rowTmpl = $('#community_smartstream_maxTmpl_return').html();
                        var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                        var arr = new Array();
                        $.map(_d.notification,function(_data){
                            arr.push(tmp(_data));
                        });
                        var prex = ['max_', 'max_', 'max_'];
                        var line = $('#community_' + prex[_displayStatus] + notID + '_line');
                        line.remove();
                        var body = $('#community_' + prex[_displayStatus] + notID);
                        body.replaceWith(arr.join(''));
						if (_displayStatus == 2) {
							searchResultPageTmpl.find('.ss_title').highlight(_searchKeyword);
							searchResultPageTmpl.find('.ss_entity').highlight(_searchKeyword);
						}
                    },{ notificationId:notID,type: notType, targetId: tagID,sync:false,source:source});//true
                };
                show_ss_topic_detail_win_with_iframe(source,url, notID,notType,tagID,creatDate,notText,commentListPageSize,cb);
            },
            showDetailWindow : function (source,notID,notType,tagID,creatDate,notText,commentListPageSize){
                var cb = function () {
                    Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null){
                            Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                            return;
                        }

                        //var rowTmpl = maxTmpl;
						var rowTmpl = $('#community_smartstream_maxTmpl_return').html();
                        var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                        var arr = new Array();
                        $.map(_d.notification,function(_data){
                            arr.push(tmp(_data));
                        });
                        var prex = ['max_', 'max_', 'max_'];
                        var line = $('#community_' + prex[_displayStatus] + notID + '_line');
                        line.remove();
                        var body = $('#community_' + prex[_displayStatus] + notID);
                        body.replaceWith(arr.join(''));
						if (_displayStatus == 2) {
							searchResultPageTmpl.find('.ss_title').highlight(_searchKeyword);
							searchResultPageTmpl.find('.ss_entity').highlight(_searchKeyword);
						}
                    },{ notificationId:notID,type: notType, targetId: tagID,sync:false,source:source});//true
                };
                show_ss_topic_detail_win(source,notID,notType,tagID,creatDate,notText,commentListPageSize, cb, true,_enableJoin);
            },
            onFilterClicked : function (e) {
                _filter = e.item.attributes.value.value;
                var text = $(e.item).find('span')[0].textContent;
                if (text == 'Unanswered') {
                    var hottest = $('#community_ss_order_hottest');
                    hottest.attr('class',"right wp_mt_3 wp_mr_20 wp_fz_12");
                    hottest.css('color','#000000');
                    hottest.attr('onclick','');
                    $('#community_ss_order_recent').css('color','#a6a6a6');
                    _order = '0';
                } else {
                    if (text == 'All') {
                        text = 'Filter Posts';
                    }
                    var hottest = $('#community_ss_order_hottest');
                    hottest.attr('class',"right wp_mt_3 wp_mr_20 wp_fz_12 smartsteam_clickable");
                    hottest.attr('onclick','community_smartstream.onHottestOrderClicked();');
                }
                var self = this;
                $('#community_filterMenu_selected').text(text);
                searchPageTmpl.hide();
                if(useragent == 'ipad'){
                    maxPageTmpl.show();
                }else{
                    maxPageTmpl.parent().show();  
                }
                
                self.maxTmp();
            },
            onLickedCountClicked : function (element, notificationId) {
                var count = parseInt(element.innerHTML);
                if (!count || count == 0) {
                    return;
                }
                var likeUsersData={ targetId:notificationId,pageSize: 200, pageNumber: 0};
                Workport.StreamAPI.getLikeByNotify(function(result,_c){
                    if(result){
                        if(result.length > 0 && result[0].LikedUsersDetails){
                            if(result[0].LikedUsersDetails.length > 0){
                                var data=result[0].LikedUsersDetails;
                                var tmlt = kendo.template($('#community_ss_window_tmpl_liked_users').html(),{useWithBlock:false});
                                var arr = [];
                                $.map(data,function(_data){
                                    arr.push(tmlt(_data));
                                });
                                userListScroll = $('#community_ss_window_users_list_scroll');
                                userListScroll.html(arr.join(''));
                                arr.length = 0;
                                window_liked_users.data('kendoWindow').title('Liked Users');
								window_liked_users.prev().find("span.k-i-close").attr("id","community_liked_users_close_button");

                                var _winMaxHeight = Math.floor($(window).height() * 0.9) - 20;
                                if (userListScroll.height() > _winMaxHeight) {
                                    userListScroll.slimScroll({wheelStep: 20, height: _winMaxHeight, disableFadeOut: true});
                                } else {
                                    window_liked_users.height('auto');
                                }
                                window_liked_users.data('kendoWindow').center();
                                window_liked_users.data('kendoWindow').open();
                            }
                        }else{
                            Workport.utils.alertMsg("", "LikedUsersDetails is null.", function(_data){});
                        }
                    }else{
                        Workport.utils.alertMsg("", "Liked users list response is Null.", function(_data){});
                    }
                },likeUsersData);
            },
            onShareButtonClicked : function () {
                var self = this;
                var cb = function () {
//                    self.doTop();
                    setTimeout(function () {
                        self.maxTmp();
                    }, 200);
                };
                smartstreamShareWinFunc.share_win_create(cb, _communityName, _communityID, 'C');
            },
            onSearchClicked : function () {
				if($("#ss_topic_began").is(":visible"))
					return;
                var searchDisplay = searchPageTmpl.css('display');
                if (!searchDisplay || searchDisplay == 'block') {
                    this.onBackToAllClicked();
                    return;
                }
                $('#community_ss_search_keywords_input').val('');
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                searchPageTmpl.show();
                searchResultContainer.hide();
                _offset = '';
//                _displayStatus = 2;
                _searchKeyword = '';
                _searchCount = 0;
            },
			onTagsClick: function(tag){
				maxPageTmpl.off('*');
				maxPageTmpl.empty();
				searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
                searchPageTmpl.show();
                searchResultContainer.hide();
                _offset = '';
//                _displayStatus = 2;
                _searchKeyword = '';
                _searchCount = 0;
				$('#community_ss_search_keywords_input').val(tag);
				community_smartstream.doSearch();
			},
            onBackToAllClicked : function () {
                searchPageTmpl.hide();
                if(useragent == 'ipad'){
                    maxPageTmpl.show();
                }else{
                    maxPageTmpl.parent().show();  
                }
                _displayStatus = 1;
                this.maxTmp();
            },
            doSearch : function () {
                var self = this;
                _next = false;
                var searchBar = $('#community_ss_search_keywords_input');
                _searchKeyword = searchBar.val();
                /*if($.trim(_searchKeyword) == "") {
                    searchBar.kendoTooltip({
                        content: 'Please input the keywords.',
                        position: "right",
                        showOn: false
                    });
                    searchBar.data('kendoTooltip').show();
                    return;
                }*/

                var searchBar_length = searchBar.kendoTooltip({
                                    content: 'Please input the keywords.',
                                    position: "right",
                                    showOn: false,
                                    show: function() {
                                            isShowUserNameInfo=true;
                                        },
                                    hide: function() {
                                            isShowUserNameInfo=false;
                                        }
                                }).data('kendoTooltip');
				searchBar.on('input',function(e){
                    searchBar_length.hide();
                });
                if($.trim(_searchKeyword) == "") {
                    searchBar_length.show();
					return;
                }
                searchResultPageTmpl.off('*');
                searchResultPageTmpl.empty();
				maxPageTmpl.off('*');
				maxPageTmpl.empty();
                _searchOffset = '';
                _displayStatus = 2;
                _searchCount = 0;
                var data = {key:$.param({key:_searchKeyword}).substring(4),pageSize:_pageSize,type:"C",targetId:_communityID, offset : _searchOffset,sync:false};
				if($('#community_ss_body_search_results').is(":visible"))
					self._loader.setContent($('#community_ss_body_search_results'),{hasMask:false,imgColor:'black',text:'Loading',position:'center',textCSS:{'color':'black'}});
				else
					self._loader.setContent($('#community_ss_body_max'),{hasMask:false,imgColor:'black',text:'Loading',position:'center',textCSS:{'color':'black'}});
				self._loader.show();
                Workport.StreamAPI.searchStream(function(_d,_code) {
					self._loader.hide();
                    if(!_d){
                        Workport.utils.alertMsg("", 'network error!', function(_data){});
                        return ;
                    }
                    if(!_d.notification){
                        searchResultContainer.show();
                        $('#community_ss_body_search_count').text(' > Showing 0 result(s) for ' + _searchKeyword);
                        if (_searchCount == 0) {
                            searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                        }
                    }else {
                        _next = true;
                        maxPageTmpl.off('*');
                        maxPageTmpl.empty();
                        //maxPageTmpl.parent().hide();
                        searchResultContainer.show();
                        self.render(_d.notification);
                        _searchCount += _d.notification.length;
                        _searchOffset = _d.notification.pop().LastModifiedDate;
                        $('#community_ss_body_search_count').text(' > Showing ' +_searchCount + ' result(s) for ' + _searchKeyword);
                        if (_searchCount == 0) {
                            searchResultPageTmpl.html('<p style="font-size: 12px; text-align: center;width: 768px;margin-top: 25px;">No results for <span style="color: #ff0000">'+_searchKeyword+'</span>.</p>');
                        }
                    }
                }, data);

            },
            onRecentOrderClicked : function () {
                _order = '0';
                $('#community_ss_order_hottest').css('color','#000000');
                $('#community_ss_order_recent').css('color','#a6a6a6');
                this.maxTmp();
            },
            onHottestOrderClicked : function () {
                _order = '1';
                $('#community_ss_order_hottest').css('color','#a6a6a6');
                $('#community_ss_order_recent').css('color','#000000');

                this.maxTmp();
            },
            onExpertCountClicked : function (notId, notType, targetId) {
                Workport.CommunityAPI.getExport(function (data) {
                    if (data && data.Users) {
                        var data = data.Users;
                        var tmlt = kendo.template($('#community_ss_window_tmpl_expert_users').html(), {useWithBlock: false});
                        var arr = [];
                        $.map(data, function (_data) {
                            arr.push(tmlt(_data));
                        });
                        userListScroll = $('#community_ss_window_users_list_scroll');
                        userListScroll.html(arr.join(''));
                        arr.length = 0;
                        window_liked_users.data('kendoWindow').title('Experts');
                        window_liked_users.data('kendoWindow').center();
                        window_liked_users.data('kendoWindow').open();
                                
                        var _winMaxHeight = Math.floor($(window).height() * 0.9) - 20;
                        if (userListScroll.height() > _winMaxHeight) {
                            userListScroll.slimScroll({wheelStep: 20, height: _winMaxHeight, disableFadeOut: true});
                        } else {
                            window_liked_users.height("auto");
                        }
                    }
                },{pagePosition : 0, pageSize: 200, notificationType:notType,targetId:targetId, notificationId:notId});
            },
            onExpertClicked : function (notId, targetId, tags, notType,source) {
                var cb = function () {
                    Workport.StreamAPI.getStreamByNotify(function(_d,_code){
                        if(!_d){
                            Workport.utils.alertMsg("", 'network error!', function(_data){});
                            return ;
                        }
                        if(_d.notification==null){
                            Workport.utils.alertMsg("", "Your update has been deleted successfully.", function(_data){});
                            return;
                        }

                        var rowTmpl = maxTmpl;
                        var tmp = kendo.template($.trim(rowTmpl),{useWithBlock:false});
                        var arr = new Array();
                        $.map(_d.notification,function(_data){
                            arr.push(tmp(_data));
                        });
                        var prex = ['max_', 'max_', 'max_'];
                        var line = $('#community_' + prex[_displayStatus] + notId + '_line');
                        line.remove();
                        var body = $('#community_' + prex[_displayStatus] + notId);
                        body.replaceWith(arr.join(''));
                    },{ notificationId:notId,type: notType, targetId: targetId,sync:false,source:source});//true
                };
                commSelectStaffWinFunc.open(notId, targetId, tags, cb);
            },
			onShareEamilClicked : function (title,text) {
				share_email_win.open(title,text);
			},
            onStreamButtonClicked : function () {
                $('.community_menu_icons').hide();
                $('#community_menu_icons_for_stream_selected').show();

                $('#community_document_filter').hide();
                $('#community_filterMenu').show();

                $('#community_order_for_stream').show();
                $('#community_order_for_document').hide();
                searchPageTmpl.hide();
                if(useragent == 'ipad'){
                    maxPageTmpl.show();
                }else{
                    maxPageTmpl.parent().show();  
                }
                $('#community_document_max').hide();
                this.maxTmp();
            },
            onDocumentButtonClicked : function () {
                $('.community_menu_icons').hide();
                $('#community_menu_icons_for_document_selected').show();
                $('#community_filterMenu').hide();
                $('#community_menu_icons_for_document_selected i').removeClass('wp_ml_50').addClass('wp_ml_8');
//                $('#community_document_filter').show();
                $('#community_order_for_document').show();
                $('#community_order_for_stream').hide();
                searchPageTmpl.hide();
                 if(useragent == 'ipad'){
                    maxPageTmpl.hide();
                }else{
                    maxPageTmpl.parent().hide();  
                }
                $('#community_document_max').show();
                communityDocuments.refreshAll();
            },
            onDocumentOrderByNameClicked : function () {
                if (communityDocuments.orderByName()) {
                    $('#community_ss_order_name_down').hide();
                    $('#community_ss_order_name_up').show();
                } else {
                    $('#community_ss_order_name_down').show();
                    $('#community_ss_order_name_up').hide();
                }
            },
            onDocumentOrderByTimeClicked : function () {
                if (communityDocuments.orderByTime()) {
                    $('#community_ss_order_time_down').hide();
                    $('#community_ss_order_time_up').show();
                } else {
                    $('#community_ss_order_time_down').show();
                    $('#community_ss_order_time_up').hide();
                }
            },
            onStickyClicked : function (element,notID,comId, enalbe) {
                var action = enalbe=='false' ? '0' : '1';
                enalbe = enalbe == 'false' ? 'true' : 'false';
                Workport.StreamAPI.setSticky(function (_d) {
                    if(_d.ResponseCode=="WP1008"){
                        $(element).attr('onclick','community_smartstream.onStickyClicked(this,"' + notID + '","' + comId + '","'+enalbe+'")');
                        $(element).attr('class',enalbe == 'true'? 'main_smartstream_q_8_8 smartsteam_clickable right':'main_smartstream_p_8_8 smartsteam_clickable right');
						$(element).attr('title',enalbe == 'true'? 'Unpin':'Pin');
                    }else{
                        Workport.utils.alertMsg("", _d.ResponseMessage, function(){});
                    }
                }, {notificationId:notID, communityId:comId, action :action});
            },
            onDisappear : function () {
                delete communityDocuments;
                resetUI();
            },
            render:function(_rowData){
                var rowTmpl = maxTmpl;
                var tmp = kendo.template($.trim(rowTmpl),{sueWithBlock:false});
                var arr = new Array();
                var rowHtml;
                $.map(_rowData,function(_data){
                    arr.push(tmp(_data));   
                });

                var bodyArr = ['#community_ss_body_max','#community_ss_body_max','#community_ss_body_search_results'];
                var body = bodyArr[_displayStatus];
                _insertOrder ? $(arr.join('')).appendTo(body) : $(arr.join('')).prependTo(body);
                arr.length = 0 ;
                var pageArr = [maxPageTmpl, maxPageTmpl, searchResultPageTmpl];
                var page = pageArr[_displayStatus];
                if(useragent != 'ipad'){
                    page.slimscroll({});
                }
                if (_displayStatus == 2) {
                    searchResultPageTmpl.find('.ss_title').highlight(_searchKeyword);
                    searchResultPageTmpl.find('.ss_entity').highlight(_searchKeyword);
//                    searchResultPageTmpl.highlight(_searchKeyword);
                }
                bodyArr.length = 0;
                pageArr.length = 0;
                if (_displayStatus == 0 && (!_rowData || _rowData.length == 0) && !_offset && _filter == '0' && _tlatest == '') {
                    $('#community_ss_body_max').html('<div id="ss_topic_began" style="margin-left: 485px;"><img src="imgs/beganSmartSream.png"></div>');
                    $('#community_ss_body_max').css('margin-top','0px');
                } else {
                    $('#community_ss_body_max').css('margin-top','15px');
                }
				$('#community_smartsteamTpl').find('.main_common_j_11_11').addClass('smartsteam_clickable');
            },
            exportInterface : function (comId, comName, callback, enableJoin) {
                var self = this;
                win = $('#community_smartstream_window').kendoWindow({
                    width:750,
                    height:600,
                    modal : true,
                    draggable: false,
                    resizable: false,
                    close : function () {
                        if(useragent == 'ipad'){
                            $('body').unbind('touchmove');
                            $('#community_smartstream_window').unbind('touchmove');
                        }
                        self.onDisappear();
                        if (callback) {
                            callback ();
                        }
                        documents_min_MySavedFiles_ScrollViewController.resetLoader();
                    },
                    open:function(){
                        if(useragent == 'ipad'){
                            $('body').bind('touchmove',function(event){event.preventDefault()});
                            $('#community_smartstream_window').bind('touchmove',function(event){event.stopPropagation()});
                            $('#community_smartstream_window').find('.km-scroll-header').remove()
                            $('#community_smartstream_window').find('.km-scroll-container').remove()
                            $('#community_smartstream_window').find('.km-touch-scrollbar').remove()
                        }
                    }
                });
                var loaderDefOptions = {imgColor:'black', textCSS:{'color':'black'}};
                var loader = new Workport.Loader($('#community_smartstream_window'), loaderDefOptions);
                documents_min_MySavedFiles_ScrollViewController.setLoader(loader);
                //              
                win.data('kendoWindow').center();
                win.data('kendoWindow').open();
				 if(useragent == 'ipad'){
                    maxPageTmpl.show();
                }else{
                    maxPageTmpl.parent().show();  
                }
				var titleHtml = '<span style="max-width: 570px" class="text-overflow left">'+comName+'</span><i id="smartskipicon" title="View Community Profile" class="main_smartstream_u_8_8 wp_ml_5 wp_mt_3 community_hand left"></i>';
                $('#community_smartstream_window_wnd_title').html(titleHtml);
                this.init($('#community_smartstream_window'), comId, comName, enableJoin);
                $('#smartskipicon').on({
                    click:function(e){
                        $('#community_smartstream_window').data("kendoWindow").close();
                        community_profile_controller.initProfilePage(comId);
                    }
                });
            }
        };
    })();
}

$(function () {
    return;
    community_smartstream.exportInterface('201442117348305', 'community name');
});